#include "Comm.hpp"
#include <sys/ipc.h>
#include <sys/shm.h>
 #include <fcntl.h>
#include <stdio.h>
#include <cstring>

 #include <sys/mman.h>
#include <sys/stat.h>        /* For mode constants */
#include <fcntl.h>           /* For O_* constants */

int main()
{
    int shmfd= shm_open(SHM_PATH, O_RDWR,0664);//获取共享内存

    char* p= (char*)mmap(nullptr, SHM_SIZE, PROT_READ| PROT_WRITE, MAP_SHARED, shmfd, 0);
    printf("%p\n",p);
    int wfd= open("fifo",O_WRONLY);

    char buf[1024];
    while(1)
    {
        printf("输入你想对服务器说的：");
        fflush(stdout);

        int n= read(0, buf, 1023);
        buf[n-1]= 0;//将\n弄成\0
        if(strcmp(buf,"quit")== 0)
        {
            close(wfd);
            munmap(p, SHM_SIZE);
            break;
        }

        strcpy(p, buf);
        int tmp=1;
        write(wfd, &tmp, 4);//通知服务器数据已经准备好
    }


    return 0;
}